#include <iostream>
#include <string>
#include <memory>
#include <sstream>
#include <cstdlib>
#include "Compiler.hpp"
#include "Run.hpp"
#include "Compiler_with_Run.hpp"
#include "../Common/httplib.h"
#include "Daemon.hpp"
using namespace ns_runner;
using namespace ns_compilerRun;
using namespace httplib;
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: [./Process +  port]" << std::endl;
        exit(0);
    }
    Daemon(false,true);
    Server server;
    server.Post("/Compiler_and_Run", [](const Request &req, Response &resp)
                {
        std::string injsonstr = req.body;
        if(!injsonstr.empty())
        {
            std::string outjsonstr;
            Complie_Run::Start(injsonstr,&outjsonstr);
            resp.set_content(outjsonstr,"application/json;charset=utf-8");
        } });
    server.listen("0.0.0.0", atoi(argv[1]));
    return 0;
}
